package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysMemberApprove;
import com.zuthub.system.service.ISysMemberApproveService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 入社审批Controller
 * 
 * @author zuthub
 * @date 2021-04-17
 */
@RestController
@RequestMapping("/system/approve")
public class SysMemberApproveController extends BaseController
{
    @Autowired
    private ISysMemberApproveService sysMemberApproveService;

    /**
     * 查询入社审批列表
     */
    @PreAuthorize("@ss.hasPermi('system:approve:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMemberApprove sysMemberApprove)
    {
        startPage();
        List<SysMemberApprove> list = sysMemberApproveService.selectSysMemberApproveList(sysMemberApprove);
        return getDataTable(list);
    }

    /**
     * 导出入社审批列表
     */
    @PreAuthorize("@ss.hasPermi('system:approve:export')")
    @Log(title = "入社审批", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysMemberApprove sysMemberApprove)
    {
        List<SysMemberApprove> list = sysMemberApproveService.selectSysMemberApproveList(sysMemberApprove);
        ExcelUtil<SysMemberApprove> util = new ExcelUtil<SysMemberApprove>(SysMemberApprove.class);
        return util.exportExcel(list, "approve");
    }

    /**
     * 获取入社审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:approve:query')")
    @GetMapping(value = "/{approveId}")
    public AjaxResult getInfo(@PathVariable("approveId") Long approveId)
    {
        return AjaxResult.success(sysMemberApproveService.selectSysMemberApproveById(approveId));
    }

    /**
     * 新增入社审批
     */
    @PreAuthorize("@ss.hasPermi('system:approve:add')")
    @Log(title = "入社审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMemberApprove sysMemberApprove)
    {
        return toAjax(sysMemberApproveService.insertSysMemberApprove(sysMemberApprove));
    }

    /**
     * 申请入社
     */
    @CrossOrigin
    @PostMapping("/form")
    public AjaxResult form(@RequestBody SysMemberApprove sysMemberApprove)
    {
        return toAjax(sysMemberApproveService.insertSysMemberApprove(sysMemberApprove));
    }

    /**
     * 入社审批通过
     * @param sysMemberApprove
     * @return
     */
    @CrossOrigin
    @PostMapping("/yes")
    public AjaxResult approve(@RequestBody SysMemberApprove sysMemberApprove) {
        return toAjax(sysMemberApproveService.approveMember(sysMemberApprove));

    }

    @GetMapping("/batchyes/{approveIds}")
    public AjaxResult approveBatch(@PathVariable("approveIds") long[] approveIds){
        return toAjax(sysMemberApproveService.approveBatch(approveIds));
    }

    /**
     * 修改入社审批
     */
    @PreAuthorize("@ss.hasPermi('system:approve:edit')")
    @Log(title = "入社审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMemberApprove sysMemberApprove)
    {
        return toAjax(sysMemberApproveService.updateSysMemberApprove(sysMemberApprove));
    }

    /**
     * 删除入社审批
     */
    @PreAuthorize("@ss.hasPermi('system:approve:remove')")
    @Log(title = "入社审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{approveIds}")
    public AjaxResult remove(@PathVariable Long[] approveIds)
    {
        return toAjax(sysMemberApproveService.deleteSysMemberApproveByIds(approveIds));
    }
}
